home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_03 / allison / tlocale.c < prev   
C/C++ Source or Header  |  1995-01-03  |  2KB  |  79 lines

  1. LISTING 7 - Shows the affect of locale settings on the decimal
  2. point character and time formatting
  3.  
  4. /* tlocale.c:   Illustrates locales -
  5.  *
  6.  *      Compiled in Visual C++ under Windows NT 3.5
  7.  */
  8.  
  9. #include <locale.h>
  10. #include <stdio.h>
  11. #include <time.h>
  12.  
  13. void print_stuff(void);
  14.  
  15. main()
  16. {
  17.     /* First in the C locale */
  18.     puts("In the C locale:");
  19.     print_stuff();
  20.  
  21.     /* Now try German */
  22.     puts("\nIn the German locale:");
  23.     setlocale(LC_ALL,"german");
  24.     print_stuff();
  25.  
  26.     /* Now try American */
  27.     puts("\nIn the American locale:");
  28.     setlocale(LC_ALL,"american");
  29.     print_stuff();
  30.  
  31.     /* Now try Italian */
  32.     puts("\nIn the Italian locale:");
  33.     setlocale(LC_ALL,"italian");
  34.     print_stuff();
  35.     return 0;
  36. }
  37.  
  38. void print_stuff(void)
  39. {
  40.     char text[81];
  41.     time_t timer = time(NULL);
  42.     struct lconv *p = localeconv();
  43.  
  44.     printf("decimal pt. == %s\n",p->decimal_point);
  45.     printf("currency symbol == %s\n",p->int_curr_symbol);
  46.     printf("%.2f\n",1.2);
  47.     strftime(text,sizeof text,"%A, %B %d, %Y (%x)\n",
  48.              localtime(&timer));
  49.     puts(text);
  50. }
  51.  
  52. In the C locale:
  53. decimal pt. == .
  54. currency symbol == 
  55. 1.20
  56. Tuesday, January 03, 1995 (01/03/95)
  57.  
  58.  
  59. In the German locale:
  60. decimal pt. == ,
  61. currency symbol == DEM
  62. 1,20
  63. Dienstag, Januar 03, 1995 (03.01.95)
  64.  
  65.  
  66. In the American locale:
  67. decimal pt. == .
  68. currency symbol == USD
  69. 1.20
  70. Tuesday, January 03, 1995 (01/03/95)
  71.  
  72.  
  73. In the Italian locale:
  74. decimal pt. == ,
  75. currency symbol == ITL
  76. 1,20
  77. marted∞, gennaio 03, 1995 (03/01/95)
  78.  
  79.